import {cache} from '../cache';
const devices = {
    "Apple A7 GPU": {
        1136: ["iPhone 5", "iPhone 5s"],
        2048: ["iPad Air", "iPad Mini 2", "iPad Mini 3"]
    },

    "Apple A8 GPU": {
        1136: ["iPod touch (6th generation)"],
        1334: ["iPhone 6"],
        2001: ["iPhone 6 Plus"],
        2048: ["iPad Air 2", "iPad Mini 4"]
    },

    "Apple A9 GPU": {
        1136: ["iPhone SE"],
        1334: ["iPhone 6s"],
        2001: ["iPhone 6s Plus"],
        2224: ["iPad Pro (9.7-inch)"],
        2732: ["iPad Pro (12.9-inch)"]
    },

    "Apple A10 GPU": {
        1334: ["iPhone 7"],
        2001: ["iPhone 7 Plus"]
    }
};

function getCanvas() {
    return document.createElement('canvas');
}

function getGl() {
    let canvas=getCanvas();
    return canvas&&canvas.getContext&&canvas.getContext('experimental-webgl');
}

export const getGlRendererRaw=()=>{
    let gl=getGl();
    if(!gl||!gl.getExtension){
        return 'unknown';
    }
    let debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
    if(debugInfo==null){
        return 'unknown';
    }
    return gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
};

export const getGlRenderer=cache(getGlRendererRaw);

export const getScreenMax=()=>{
    return Math.max(screen.width, screen.height) * (window.devicePixelRatio || 1);
};
export const getScreen=()=>{
    const {width,height}=window.screen;
    return [
        Math.max(width,height),
        Math.min(width,height),
        window.devicePixelRatio||1
    ]
};
export const getDeviceString=()=>{
    const glRender=getGlRenderer();
    const screen=getScreen().join('*');
    return [glRender,screen].join(';');
};